<?php
require('utils/conn.php');
require('utils/session.php');
function saveChat(){
	$userId=Bluebirdhsz_Session::get('chatUserid');
	$chatTo=@$_GET['chatto'] or 0;
	if(false==$userId||0==$chatTo)	return showError("出错了");
	$json=addslashes($_POST['json']);
	$db=new conn();
	if($userId>(int)$chatTo){
		$usera=$chatTo;
		$userb=$userId;
		$row="user_a_msg";
	}else{
		$usera=$userId;
		$userb=$chatTo;
		$row="user_b_msg";
	}
	$db->query("update chatrelation set {$row}=1 where user_a={$usera} and user_b={$userb}");
	$db->query("insert into chatrecord(reqUser,toUser,message,timeStamp) values ({$userId},{$chatTo},'{$json}',".time().")");
	$db->close();
	return Array('result'=>1);
}
echo json_encode(saveChat());
?>